/*******************************************************************************
 Configuration Information:
 Repository: Integrity Source
 Name      : $RCSfile: AR_CD_ColTqFil.c $
 Version   : $Revision: 1.4 $
 Author    : $Author: Jack Jin (JinC5) $
 Date      : $Date: 2018/09/18 19:53:59IST $
 Location  : $ProjectName: /Steering/Projects/Geely/CMA_DP/PR48756_LVS_ENG_APP_Geely_CMA_EPS_DP_SYS_HRoom_AP/30_Software/3040_Design/S2-Application/01-Development/V00-Mainline/04-Components/ActiveReturn_Ear/Source/project.pj $
********************************************************************************

   ZF Friedrichshafen AG owns the copyright in this document and associated
   documents and all rights are reserved.  These documents must
   not be used for any purpose other than that for which they
   are supplied and must not be copied in whole or in part or
   disclosed to others without prior written consent of ZF Friedrichshafen AG.
   Any copy of this drawing or document made by any method
   must also include a copy of this legend.

   (C) ZF Friedrichshafen AG 2018

*******************************************************************************/
/**************************************************************************************************\
 *** 
 *** Simulink model       : AR_CD_ColTqFil_tl
 *** TargetLink subsystem : AR_CD_ColTqFil_tl
 *** Codefile             : AR_CD_ColTqFil.c
 ***
 *** Generated by TargetLink, the dSPACE production quality code generator
 *** Model version: 1.619
 *** Generation date: 2018-09-18 14:55:04
 ***
 *** CODE GENERATOR OPTIONS:
 *** Code generation mode                     : AUTOSAR
 *** AUTOSAR version                          : 4.2.2
 *** Compiler                                 : <unknown>
 *** Target                                   : Generic
 *** ANSI-C compatible code                   : yes
 *** Code Optimization                        : enabled
 *** Constant style                           : decimal
 *** Clean code option                        : enabled
 *** Logging mode                             : Do not log anything
 *** Code Coverage                            : disabled
 *** Generate empty conditional branches      : disabled
 *** Loop unroll threshold                    : 5
 *** Shift mode                               : automatic
 *** Handle unscaled SF expr. with TL type    : enabled
 *** Assignment of conditions                 : AllBooleanOutputs 
 *** Scope reduction only to function level   : disabled
 *** Exploit ranges if not erasable           : disabled
 *** Exploit Compute Through Overflow         : never
 *** Linker sections                          : enabled
 *** Enable Assembler                         : disabled
 *** Variable name length                     : unlimited
 *** Use global bitfields                     : disabled
 *** Stateflow: use of bitfields              : enabled
 *** State activity encoding limit            : 8
 *** Omit zero inits in restart function      : disabled
 *** Share functions between TL subsystems    : disabled
 *** Generate 64bit functions                 : disabled
 *** Inlining Threshold                       : 6
 *** Line break limit                         : 100
 *** Target optimized boolean data type       : enabled
 *** Keep saturation elements                 : disabled
 *** Extended variable sharing                : disabled
 *** Extended lifetime optimization           : enabled
 *** Style definition file                    : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\Con
 ***                                            fig\codegen\cconfig.xml
 *** Root style sheet                         : C:\Program Files\dSPACE TargetLink 4.2\Matlab\Tl\XML
 ***                                            \CodeGen\Stylesheets\TL_CSourceCodeSS.xsl
 ***
 *** SUBSYS                   CORRESPONDING SIMULINK SUBSYSTEM
 *** SAR_CD_071               AR_CD_ColTqFil_tl
 *** SAR_CD_072               AR_CD_ColTqFil_tl/AR_CD_ColTqFild
 *** SAR_CD_073               AR_CD_ColTqFil_tl/DocFunction
 *** SAR_CD_074               AR_CD_ColTqFil_tl/IncludeAppHeader
 *** SAR_CD_075               AR_CD_ColTqFil_tl/AR_CD_ColTqFild/AR_CD_ColTqFild_ColTqAtf2
 *** SAR_CD_076               AR_CD_ColTqFil_tl/AR_CD_ColTqFild/ZFDivA_fabs
 *** SAR_CD_077               AR_CD_ColTqFil_tl/AR_CD_ColTqFild/AR_CD_ColTqFild_ColTqAtf2/DocBlock
 *** SAR_CD_078               AR_CD_ColTqFil_tl/AR_CD_ColTqFild/AR_CD_ColTqFild_ColTqAtf2/DocBlock/E
 ***                          mptySubsystem
 *** SAR_CD_079               AR_CD_ColTqFil_tl/DocFunction/EmptySubsystem
 *** 
 *** SUBSYS                   CORRESPONDING MODEL BLOCK (REFERENCED MODEL)
 *** 
 *** SF-NODE   CORRESPONDING STATEFLOW NODE                           DESCRIPTION
 *** 
 *** TargetLink version      : 4.2p2 from 27-Nov-2017
 *** Code generator version  : Build Id 4.2.0.33 from 2017-11-28 14:39:24

\**************************************************************************************************/

#ifndef AR_CD_COLTQFIL_C
#define AR_CD_COLTQFIL_C

/*----------------------------------------------------------------------------*\
  DEFINES (OPT)
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INCLUDES
\*----------------------------------------------------------------------------*/

#include "Rte_ActiveReturnSwc.h"
#include "AR_CD_ColTqFil_tl_lut.h"
#include "AR_CD_ColTqFil.h"
#include "ActiveReturnSwc_Library.h"

/*----------------------------------------------------------------------------*\
  ENUMS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  DEFINES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  TYPEDEFS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  VARIABLES
\*----------------------------------------------------------------------------*/

/******************************************************************************\
   VC_STRUCT_InitAtDef: Used for global struct variables. Initialised at definition. Creates access 
   functions (get and set). | Width: N.A.
\******************************************************************************/
struct tAR_CD_ColTqFil_tag var_AR_CD_ColTqFil = {
   0, /* EarColTqFildIndex */
   0.F /* EarColTqFildFraction */
};

/* Custom code: AR_CD_ColTqFil_tl/IncludeAppHeader/CC_AppHeaderInclude << declaration code >> */
#include "Rte_ActiveReturnSwc.h"
/*----------------------------------------------------------------------------*\
  PARAMETERIZED MACROS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION PROTOTYPES
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  INLINE FUNCTIONS
\*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*\
  FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/

/**************************************************************************************************\
 ***  FUNCTION:
 ***      AR_CD_ColTqFil
 *** 
 ***  DESCRIPTION:
 ***      
 *** 
 ***  PARAMETERS:
 ***      Type               Name                Description
 ***      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ***      Nm                 ColTq               
 ***      Float32            ColTqAtfA1          
 ***      Float32            ColTqAtfA2          
 ***      Float32            ColTqAtfB0          
 ***      Float32            ColTqAtfB1          
 ***      Float32            ColTqAtfB2          
 ***      Nm                 EarLkaColTq         
 ***      Nm                 IpTqOvly            
 ***
 ***  RETURNS:
 ***      void
 ***
 ***  SETTINGS:
 ***
\**************************************************************************************************/
void AR_CD_ColTqFil(Nm ColTq, Float32 ColTqAtfA1, Float32 ColTqAtfA2, Float32 ColTqAtfB0, Float32
  ColTqAtfB1, Float32 ColTqAtfB2, Nm EarLkaColTq, Nm IpTqOvly)
{
   /* SLLocal: Default storage class for local variables | Width: 32 */
   float32 SAR_CD_072_Sum;
   Nm SAR_CD_072__Filter_Bypass_Switch;
   Nm SAR_CD_075_Divide1;
   Float32 SAR_CD_075_Sum;
   Float32 SAR_CD_075_Unit_Delay4;
   float32 SAR_CD_076_Switch;

   /* SLStaticLocalInit: Default storage class for static local variables with initvalue | Width: 32
    */
   static Float32 X_SAR_CD_075_Unit_Delay1 = 0.F;
   static Float32 X_SAR_CD_075_Unit_Delay2 = 0.F;
   static Float32 X_SAR_CD_075_Unit_Delay3 = 0.F;
   static Float32 X_SAR_CD_075_Unit_Delay4 = 0.F;

   /* Sum: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /Sum */
   SAR_CD_072_Sum = EarLkaColTq + ColTq + IpTqOvly;

   /* Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit Delay4 */
   SAR_CD_075_Unit_Delay4 = X_SAR_CD_075_Unit_Delay4;
   X_SAR_CD_075_Unit_Delay4 = SAR_CD_072_Sum;

   /* Sum: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Sum
      # combined # Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Product4
      # combined # Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Product3
      # combined # Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Product2
      # combined # Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Product1
      # combined # Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Product
      # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit Del
      ay2 */
   SAR_CD_075_Sum = ((SAR_CD_072_Sum * ColTqAtfB0) + (SAR_CD_075_Unit_Delay4 * ColTqAtfB1) +
    (X_SAR_CD_075_Unit_Delay3 * ColTqAtfB2)) - (ColTqAtfA1 * X_SAR_CD_075_Unit_Delay2) -
    (X_SAR_CD_075_Unit_Delay1 * ColTqAtfA2);

   /* Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit Delay1
      # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit Del
      ay2 */
   X_SAR_CD_075_Unit_Delay1 = X_SAR_CD_075_Unit_Delay2;

   /* Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit Delay3 */
   X_SAR_CD_075_Unit_Delay3 = SAR_CD_075_Unit_Delay4;

   /* Product: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Divide1 */
   if (EAR_COL_TRQ_ATF_A0 != 0.F) {
      SAR_CD_075_Divide1 = SAR_CD_075_Sum / EAR_COL_TRQ_ATF_A0;
   }
   else {
      if (SAR_CD_075_Sum < 0.F) {
         SAR_CD_075_Divide1 = -3.402823466e+38F;
      }
      else {
         SAR_CD_075_Divide1 = 3.402823466e+38F;
      }
   }

   /* Saturation: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Saturation1 */
   if (SAR_CD_075_Divide1 > 10.F) {
      /* # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit 
         Delay2 */
      X_SAR_CD_075_Unit_Delay2 = 10.F;
   }
   else {
      if (SAR_CD_075_Divide1 < -10.F) {
         /* # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Un
            it Delay2 */
         X_SAR_CD_075_Unit_Delay2 = -10.F;
      }
      else {
         /* # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Un
            it Delay2 */
         X_SAR_CD_075_Unit_Delay2 = SAR_CD_075_Divide1;
      }
   }

   /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild / Filter Bypass Switch
      AR_CD_ColTqFil_tl/AR_CD_ColTqFild / Filter Bypass Switch: Omitted comparison with constant. */
   if (Rte_CData_EAR_COL_TRQ_ATF_BYP()) {
      /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild / Filter Bypass Switch */
      SAR_CD_072__Filter_Bypass_Switch = SAR_CD_072_Sum;
   }
   else {
      /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild / Filter Bypass Switch
         # combined # Unit delay: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /AR_CD_ColTqFild_ColTqAtf2/Unit 
         Delay2 */
      SAR_CD_072__Filter_Bypass_Switch = X_SAR_CD_075_Unit_Delay2;
   }

   /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Switch
      AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Switch: Omitted comparison with constant.
      # combined # Relational: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Relational Operator */
   if (SAR_CD_072__Filter_Bypass_Switch < 0.F) {
      /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Switch
         # combined # Gain: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Gain */
      SAR_CD_076_Switch = SAR_CD_072__Filter_Bypass_Switch * -1.F;
   }
   else {
      /* Switch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /ZFDivA_fabs/Switch */
      SAR_CD_076_Switch = SAR_CD_072__Filter_Bypass_Switch;
   }

   /* IndexSearch: AR_CD_ColTqFil_tl/AR_CD_ColTqFild /Prelookup
      # combined # TargetLink outport: AR_CD_ColTqFil_tl/EarColTqFildIndex
      # combined # TargetLink outport: AR_CD_ColTqFil_tl/EarColTqFildFraction */
   TabIdxS48T3078_AR_CD_07((const float32 *) Rte_CData_EAR_ACTVN_COL_TQ_BRKPTS(), 8,
    SAR_CD_076_Switch, &(var_AR_CD_ColTqFil.EarColTqFildIndex),
    &(var_AR_CD_ColTqFil.EarColTqFildFraction));
}

/*----------------------------------------------------------------------------*\
  MODULE LOCAL FUNCTION DEFINITIONS
\*----------------------------------------------------------------------------*/
#endif /* AR_CD_COLTQFIL_C */
/*----------------------------------------------------------------------------*\
  END OF FILE
\*----------------------------------------------------------------------------*/
